﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Taula = DeltaFlex.Negoci.ConsTaules.Concepte_Albara;
using System.Globalization;

namespace DeltaFlex.Negoci
{
    [Serializable()]
    public class Concepte_Albara
    {
        #region Variables
        private int _idConcepte_Albara;
        private int _idAlbara;
        private Articles _article;
        private decimal _quantitat;
        private string _strSuperficie;
        private decimal _decimalSuperficie;
        private string _unitats;
        private decimal _pvp;
        private decimal _import;
        #endregion

        #region Atributs
        public int IdConcepte_Albara
        {
            get { return _idConcepte_Albara; }
            set { _idConcepte_Albara = value; }
        }

        public int IdAlbara
        {
            get { return _idAlbara; }
            set { _idAlbara = value; }
        }

        public Articles Article
        {
            get { return _article; }
            set { _article = value; }
        }

        public decimal Quantitat
        {
            get { return _quantitat; }
            set { _quantitat = value; }
        }

        public string StrSuperficie
        {
            get { return _strSuperficie; }
            set { _strSuperficie = value; }
        }

        public decimal DecimalSuperficie
        {
            get { return _decimalSuperficie; }
            set { _decimalSuperficie = value; }
        }

        public string Unitats
        {
            get { return _unitats; }
            set { _unitats = value; }
        }

        public decimal Pvp
        {
            get { return _pvp; }
            set { _pvp = value; }
        }

        public decimal Import
        {
            get { return _import; }
            set { _import = value; }
        }

        #region Bindings
        public string BindRefArticle
        {
            get { return _article.ReferenciaArticle; }
        }

        public string BindConcepte
        {
            get { return _article.NomArticle; }
        }

        public string BindPVP
        {
            get
            {
                return _pvp.ToString("C2", CultureInfo.CurrentCulture);
            }
        }

        public string BindImport
        {
            get
            {
                return _import.ToString("C2", CultureInfo.CurrentCulture);
            }
        }

        #endregion
        #endregion

        #region Inserts
        public static int InsertarConcepte_Albara(int idAlbara, int idArticle, decimal quantitat, string strSuperfice, decimal decimalSuperficie, string unitats, decimal pvp, decimal import)
        {
            try
            {
                return Data.Concepte_Albara.InsertarConcepte_Alabara(idAlbara, idArticle, quantitat, strSuperfice, decimalSuperficie, unitats, pvp, import);
            }
            catch { throw; }
        }
        #endregion

        #region Updates
        public static void ActualitzarConcepteAlbara(int idConcepte_Albara, int idArticle, decimal quantitat, string strSuperficie,
                                                      decimal decimalSuperficie, string unitats, decimal pvp, decimal import)
        {
            try
            {
                Data.Concepte_Albara.ActualitzarConcepteAlbara(idConcepte_Albara, idArticle, quantitat, strSuperficie, 
                                                                decimalSuperficie, unitats, pvp, import);
            }
            catch { throw; }

        }
        #endregion

        #region Selects
        public static List<Concepte_Albara> LlistarConcepte_Albarans(int idAlbara)
        {
            List<Concepte_Albara> lstConcepte_Albara = new List<Concepte_Albara>();
            IDataReader reader = null;

            try
            {
                reader = Data.Concepte_Albara.LlistarConcepte_Albarans(idAlbara);

                while (reader.Read())
                {
                    lstConcepte_Albara.Add(MapEntityFromDataReader(reader));
                }
            }
            catch { throw; }
            finally
            {
                if (reader != null) reader.Close();
            }

          return lstConcepte_Albara;

        }
        #endregion

        #region Mapeig
        public static Concepte_Albara MapEntityFromDataReader(IDataReader record)
        {
            Concepte_Albara concepte_Albara = new Concepte_Albara();

            MemberAllocation.Allocate(record, Taula.COLUMNA_IDCONCEPTE_ALBARA, ref concepte_Albara._idConcepte_Albara);
            MemberAllocation.Allocate(record, Taula.COLUMNA_IDALBARA, ref concepte_Albara._idAlbara);
            concepte_Albara._article = Articles.MapEntityFromId(record);
            MemberAllocation.Allocate(record, Taula.COLUMNA_QUANTITAT, ref concepte_Albara._quantitat);
            MemberAllocation.Allocate(record, Taula.COLUMNA_STRSUPERFICIE, ref concepte_Albara._strSuperficie);
            MemberAllocation.Allocate(record, Taula.COLUMNA_DECIMALSUPERFICIE, ref concepte_Albara._decimalSuperficie);
            MemberAllocation.Allocate(record, Taula.COLUMNA_UNITATS, ref concepte_Albara._unitats);
            MemberAllocation.Allocate(record, Taula.COLUMNA_PVP, ref concepte_Albara._pvp);
            MemberAllocation.Allocate(record, Taula.COLUMNA_IMPORT, ref concepte_Albara._import);

            return concepte_Albara;
        }

        #endregion
    }
}
